﻿using System;

namespace OrderControl {
    public class OrderDetail {
        private Commodity commodity;
        private int amount = 0;

        public Commodity Commodity {
            get => commodity;
            set => commodity = value;
        }
        public int Amount {
            get => amount;
            set {
                if (value > 0) {
                    amount = value;
                }
                else {
                    throw new OrderPropertyException("Amount cannot be less than or equal to zero.");
                }
            }
        }
        public double Price { get => commodity.UnitPrice * amount; }

        public OrderDetail(Commodity commodity, int amount) {
            this.commodity = commodity;
            this.Amount = amount;
        }

        public OrderDetail() { }

        public override string ToString() {
            return "[OrderDetail] Commodity Name: " + Commodity.Name
                + ", Unit-Price: " + Commodity.UnitPrice
                + ", Amount: " + Amount
                + ", Price: " + Price;
        }
    }
}
